#include "logindialog.h"
#include "ui_logindialog.h"
#include <QIntValidator>

LoginDialog::LoginDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LoginDialog),
    isLogin(false)
{
    ui->setupUi(this);
    ui->lineEdit_2->setValidator(new QIntValidator(0, 65535, this));
}

LoginDialog::~LoginDialog()
{
    delete ui;
}

void LoginDialog::logined()
{
    ui->pushButton->setEnabled(true);
    ui->pushButton->setText("登出");
    isLogin = true;
}

void LoginDialog::loginFailed(const QString &text)
{
    ui->infoLabel->setText(text);
    ui->pushButton->setText("登入");
    isLogin = false;
}

void LoginDialog::on_pushButton_clicked()
{
    if(isLogin == false)
    {
        ui->pushButton->setEnabled(false);
        emit login(ui->lineEdit->text(), ui->lineEdit_2->text().toShort());
    }
    else
    {
        emit unlogin();
    }
}
